#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@File ：CategoriesController.py
@Author ：zqy
@Email : zqingy@work@163.com 
@note: 
"""

from flask_restx import Namespace, Resource

# from application.Parser.CategoriesParser import CategoriesValidator
# from application.controller import register_crud_model
# from application.logic.CategoriesLogic import CategoriesLogic
from application.model.ProductModel import Category
from application.util.ResponseUtil import ResponseUtil

category_ns = Namespace('category', description='分类模块')


# categories_parser: CategoriesValidator = CategoriesValidator
# register_crud_model(
#     ns=categories_ns,
#     logic_cls=CategoriesLogic,
#     parser=categories_parser,
#     route="/categories",
#     id_type="int",
#     include_operations=["get", "list"]
# )

@category_ns.route('')
class CategoriesController(Resource):
    def get(self):
        data = [{"id": i.id, "name": i.name} for i in Category.query.all()]
        return ResponseUtil(data=data).success()
